import 'package:dio/dio.dart' hide LogInterceptor;

///创建dio联网工具类的类
class DioCreator {
  static Dio? _dio;

  DioCreator._();

  static void initDio(String baseUrl, {List<Interceptor>? interceptors}) {
    if (_dio == null) {
      BaseOptions options = BaseOptions(
        responseType: ResponseType.plain,
        baseUrl: baseUrl,
        connectTimeout: const Duration(seconds: 10),
        receiveTimeout: const Duration(seconds: 10),
      );
      _dio = Dio(options);
      interceptors?.forEach((element) {
        _dio?.interceptors.add(element);
      });
    }
  }

  static Dio getDio() => _dio!;

  static void reset() {
    _dio?.interceptors.clear();
    _dio?.close(force: false);
    _dio = null;
  }
}
